package com.wanxi.springboot.team.manage.system.controller;


import com.wanxi.springboot.team.manage.system.api.CommonResult;
import com.wanxi.springboot.team.manage.system.model.Permission;
import com.wanxi.springboot.team.manage.system.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 蒋帆
 * @since 2020-12-21
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    PermissionService permissionService;

    @PreAuthorize("hasAnyAuthority('permission:get')")
    @GetMapping("/getPermissions")
    public CommonResult getPermissions(@RequestParam("page") Integer page,@RequestParam("limit") Integer limit){
        return permissionService.getPermissions(page,limit);
    }

    @PreAuthorize("hasAnyAuthority('permission:get:all')")
    @GetMapping("/getAllPermissions")
    public CommonResult getAllPermissions(){
        return permissionService.getAllPermissions();
    }

    @PreAuthorize("hasAnyAuthority('permission:add')")
    @PostMapping("/addPermission")
    public CommonResult addPermission(@RequestBody Permission permission){
        return permissionService.addPermission(permission);
    }

    @PreAuthorize("hasAnyAuthority('permission:update')")
    @PostMapping("/updatePermission")
    public CommonResult updatePermission(@RequestBody Permission permission){
        return permissionService.updatePermission(permission);
    }

    @PreAuthorize("hasAnyAuthority('permission:delete')")
    @DeleteMapping("/deletePermission")
    public CommonResult deletePermission(@RequestParam Integer id){
        return permissionService.deletePermission(id);
    }
}
